import xlrd  # 不支持新版xlsx文件
import xlwt

# # 基本方法
# workbook = xlrd.open_workbook("Demo.xls")
# print("表数：%s" % workbook.nsheets)  # 获取sheet表数量
# table = workbook.sheet_by_index(0)
# rows_count = table.nrows    # 获取行数
# cols_count = table.ncols    # 获取列数
# print("行: %s" % rows_count)
# print("列: %s" % cols_count)
# baidu_url = table.cell(2, 0).value  # 获取第三行第一列信息
# print("第三行第一列信息： %s" % baidu_url)
# row_data = table.row_values(1)  # 获取第二行所有信息
# print("第二行所有信息： %s" % row_data)
# col_data = table.col_values(1)  # 获取第二列所有信息
# print("第二列所有信息： %s" % col_data)
# # 读整张表
# for rownumber in range(0, rows_count, 1):
#     for colnumber in range(0, cols_count, 1):
#         cell_value = table.cell(rownumber, colnumber)
#         print(cell_value)


# 封装成类
class ReadExcel():
    def __init__(self, filename, sheetname):
        self.workbook = xlrd.open_workbook(filename)
        self.sheetName = self.workbook.sheet_by_name(sheetname)

    # 读取某个坐标的值
    def read_cell(self, rowNum, colNum):
        cell = self.sheetName.cell(rowNum, colNum).value
        return cell

    # 读取行方法
    def read_row(self, rowNum):
        row_data = self.sheetName.row_values(rowNum)
        return row_data

    # 读取列方法
    def read_col(self, colNum):
        col_data = self.sheetName.row_values(colNum)
        return col_data


ReadExcelClass = ReadExcel("Demo.xls", "Demo")
print("第一行的值： %s" % ReadExcelClass.read_row(0))














